import { getOpenId, promiseRequest } from "../../../utils/index";
const app = getApp();
Page({
data: {
  actshareinfos:[],
},
onLoad(options) {
  //获取到请求类型 type 1代表我发起的,2代表我要领取的 3代表我成功领取的
  let type = options.type;
  if(type==1){
    wx.setNavigationBarTitle({
      title: '我发起的分享'
    })
    this.getmyshare();
  } else if (type == 2){
    wx.setNavigationBarTitle({
      title: '我参与的分享'
    })
    this.getmyReceive();
  } else if (type == 3) {
    wx.setNavigationBarTitle({
      title: '我的分享成果'
    })
    this.getMyReceivesSuccess();
  }
},
onShow(){
},

//openid查询我发起的活动信息
getmyshare() {
  let openid = getOpenId();
  let requestObj = {
    url: '/wxa/actshare/getMyShareInfos',
    method: 'post',
    dataobj: {openid:openid},
  };
  promiseRequest(requestObj).then((res) => {
    if (res.code == 200) {
      this.setData({
        actshareinfos: res.data.list
      })
    }
  }).catch((errMsg) => {
  });
},
//openid查询我领取的活动信息
getmyReceive() {
  let openid = getOpenId();
  let requestObj = {
    url: '/wxa/actreceive/getMyReceives',
    method: 'post',
    dataobj: { openid: openid },
  };
  promiseRequest(requestObj).then((res) => {
    if (res.code == 200) {
      this.setData({
        actshareinfos: res.data.list
      })
    }
  }).catch((errMsg) => {
  });
},
//openid查询我领取成功的活动信息
getMyReceivesSuccess() {
  let openid = getOpenId();
  let requestObj = {
    url: '/wxa/actreceive/getMyReceivesSuccess',
    method: 'post',
    dataobj: { openid: openid },
  };
  promiseRequest(requestObj).then((res) => {
    if (res.code == 200) {
      this.setData({
        actshareinfos: res.data.list
      })
    }
  }).catch((errMsg) => {
  });
},
//查看活动详情
detail(event){
  let id = event.currentTarget.dataset.id;
  wx.navigateTo({
    url: '../shareHelp/shareHelp?actId='+id,
  })
}
})